package com.magic.gre.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.magic.gre.R;
import com.magic.gre.base.activity.BaseCenterActivity;
import com.noname.lib_base_java.entity.MsgEvent;
import com.noname.lib_base_java.net.RxBus;
import com.noname.lib_base_java.util.ToastUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author: Lmoumou
 * Date: 2019-01-11 11:09
 * 文件名: ModifyNickActivity
 * 描述:
 */
public class ModifyNickActivity extends BaseCenterActivity {

    @BindView(R.id.new_nick_edt)
    EditText newNickEdt;

    public static void startThis(Context context, String oldNick) {
        Intent intent = new Intent(context.getApplicationContext(), ModifyNickActivity.class);
        intent.putExtra("oldNick", oldNick);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_modify_nick;
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        newNickEdt.setText(getIntent().getStringExtra("oldNick"));
    }

    @OnClick(value = {R.id.sure_modify_bt})
    protected void onClick(View view) {
        switch (view.getId()) {
            case R.id.sure_modify_bt:
                String nick = String.valueOf(newNickEdt.getText());
                if (TextUtils.isEmpty(nick)) {
                    ToastUtil.getInstance().showNormal(this, "请输入新的昵称");
                } else {
                    MsgEvent msgEvent = new MsgEvent(MsgEvent.MODIFY_NICK);
                    msgEvent.put("nick", nick);
                    RxBus.getInstance().post(msgEvent);
                    finish();
                }

                break;
        }
    }

}
